'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-09-29 09:19:12
LastEditTime: 2025-09-29 09:43:24
'''

class Solution:

    def search(self, nums: list[int], target: int) -> int:

        if not nums:
            return -1
        
        left, right = 0, len(nums) - 1

        # if nums[left] == target:
        #     return left
        # elif nums[right] == target:
        #     return right

        # 截断取整
        while left <= right: # 左闭区间 右闭区间 [left, right]
            mid = int(left + (right - left) / 2)
            if nums[mid] == target:
                return mid
            elif nums[mid] < target:
                left = mid + 1
            
            elif nums[mid] > target:
                right = mid - 1

        return -1
    

if __name__ == "__main__":

    arr = [9]
    t = 8
    sol = Solution()
    ans = sol.search(arr, t)
    print(ans)

